
import java.io.FileReader;
import java.io.FileWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import beans.Employee;



public class pruebaPersistObj {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JAXBContext context;
		try {

			//objeto a XML
			context = JAXBContext.newInstance(Employee.class);		
		    Marshaller m = context.createMarshaller();
		    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

		    Employee object = new Employee();
		    object.setCode("CA");
		    object.setName("Cath");
		    object.setSalary(300);
		    
		    m.marshal(object, new FileWriter(".\\src\\Person.xml"));
		    
		    
		    
		    
		    
		    
		    //XML a objeto
	        final Unmarshaller unmarshaller = context.createUnmarshaller();	       
	        //final Employee object = (Employee) unmarshaller.unmarshal(new StringReader(stringWriter.toString()));
	        final Employee object1 = (Employee) unmarshaller.unmarshal(new FileReader(".\\src\\Person.xml"));	        	       
	        //System.out.println(object1.toString());
		    
		    
		    
		    
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
